<%@page contentType="text/html;charset=UTF-8" %>
<%@page import="java.lang.*, java.io.*, java.sql.*, java.util.*" contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style type="text/css">
body 
  {  
  background-image:url(bbb.jpg);
  background-repeat:no-repeat;
  background-attachment:fixed;
  background-size: cover;
  margin:0 auto;
  text-align:center
  }
  </style>
<title>work8</title>
</head>
<body >

<%

    String url = "jdbc:mysql://localhost:3306/teststu";
    String driverName = "com.mysql.jdbc.Driver";

    String userName = "root";
    String password = "990124";
    
    Connection conn = null;
    Statement statement = null;
    ResultSet resultSet = null;
    

	String sql = "select * from teststu.student";
	 
 
	Class.forName(driverName);
	conn = DriverManager.getConnection(url, userName, password);
    statement = conn.createStatement();
     resultSet = statement.executeQuery(sql);

     
     int pageSize=10;  
     int pageCount;  
     int showPage;  
     
   //将游标移到最后一行   
     resultSet.last();  
   
     //获取最后一行的行号   
     int recordCount=resultSet.getRow();  
     
     //计算分页后的总数   
     pageCount=(recordCount%pageSize==0)?(recordCount/pageSize):(recordCount/pageSize+1);  
       
     //获取用户想要显示的页数：  
     String integer=request.getParameter("showPage");  
     if(integer==null){  
         integer="1";  
     }  
     try{showPage=Integer.parseInt(integer);  
     }catch(NumberFormatException e){  
         showPage=1;  
     }  
     if(showPage<=1){  
         showPage=1;  
     }  
     if(showPage>=pageCount){  
         showPage=pageCount;  
     }  
       
     //如果要显示第showPage页，那么游标应该移动到的position的值是：  
     int position=(showPage-1)*pageSize+1;  
     
     //设置游标的位置  
     resultSet.absolute(position);  
    %>
      <br> <br>
      <h1 align="center">学生信息表</h1>
         <table align="center" border=1>  
         <tr>   
                <td width="100px"> 学号</td>  
                <td width="100px" >课程号 </td>  
                <td width="100px">课程名 </td>  
                <td width="100px"> 学时数</td>  
                <td width="100px"> 老师</td>  
                <td width="100px"> 地点</td>  
                <td width="100px"> 学年</td>  
                 <td width="100px"> 学期</td>  
         </tr>  
         
     </table>  
       
     <%
     //用for循环显示本页中应显示的的记录  
                      
     for(int i=1;i<=pageSize;i++){  
    	 %>
    	 
    	 <table align="center" border=1>  
         <tr>   
             <td width="100px"><%=resultSet.getString(1) %></td>  
             <td width="100px"><%=resultSet.getString(2) %></td>  
             <td width="100px"><%=resultSet.getString(3) %></td>  
             <td width="100px"><%=resultSet.getString(4) %></td>  
             <td width="100px"><%=resultSet.getString(5) %></td>  
             <td width="100px"><%=resultSet.getString(6) %></td>  
             <td width="100px"><%=resultSet.getString(7) %></td>  
             <td width="100px"><%=resultSet.getString(8) %></td>  
         </tr>  
         
     </table>  
               
    <%   
     resultSet.next();  
 }     
    	 
     resultSet.close();   statement.close();   conn.close();
 %>  
 <br>   <br> 
 第<%=showPage %>页（共<%=pageCount %>页）  
 <br>  
 <a href="work8.jsp?showPage=1">首页</a>  
 <a href="work8.jsp?showPage=<%=showPage-1%>">上一页</a>  
<%   //根据pageCount的值显示每一页的数字并附加上相应的超链接  
     for(int i=1;i<=pageCount;i++){  
 %>  
         <a href="work8.jsp?showPage=<%=i%>"><%=i%></a>  
<%   }  
 %>     
 <a href="work8.jsp?showPage=<%=showPage+1%>">下一页</a>  
 <a href="work8.jsp?showPage=<%=pageCount%>">末页</a>  
 <!-- 通过表单提交用户想要显示的页数 -->  
 <form action="" method="get">  
     跳转到第<input type="text" name="showPage" size="4">页  
     <input type="submit" name="submit" value="跳转">  
 </form>     
     
      
  

</body>
</html>